#ifndef MAINWINDOW_H
#define MAINWINDOW_H

/**
Nectarine Utility Project is a software interface for the web system 'demovibes'
Copyright (C) 2010  Alexandre LAURENT

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

website: http://code.google.com/p/nectarine-utility-project/
e-mail: lw.demoscene@gmail.com
**/

#include <QtGui/QMainWindow>

#include <QString>

#include "Parser/onelinerxmlparser.h"

class QTabWidget;

class QAction;
class QTimer;
class QCloseEvent;

class OnelinerWidget;
class QueueWidget;
class PlayerWidget;

class WebClient;

class StreamPlayer;

class SongInfoDialog;
class ArtistInfoDialog;
class GroupInfoDialog;
class CompilationInfoDialog;
class UserInfoDialog;
class FavsDialog;
class NewsPromptDialog;

class MainWindow : public QMainWindow
{
    Q_OBJECT

private:

    QTabWidget* pTabWidget;

    OnelinerWidget* pOnelinerWidget;
    QueueWidget* pQueueWidget;
    PlayerWidget* pPlayerWidget;

    // Web engine
    WebClient* pWebClient;

    // Stream Player
    StreamPlayer* pPlayer;

    QList<SongInfoDialog*> listPSID;
    QList<ArtistInfoDialog*> listPAID;
    QList<GroupInfoDialog*> listPGID;
    QList<CompilationInfoDialog*> listPCID;
    QList<UserInfoDialog*> listPUID;
    QList<FavsDialog*> listPFD;
    NewsPromptDialog* pNPD;

    // Menus

    QAction* pUserFavAction;
    QAction* pPlayPauseAction;
    QAction* pStopAction;
    QAction* pCheckPMAction;
    QAction* pTooglePMAutoCheckAction;

    // Application management
    QTimer* pOnelinerTimer;
    QTimer* pQueueTimer;
    QTimer* pUsersTimer;
    QTimer* pPMTimer;

    // User managemant
    bool isConnected;
    QString username;
    // Favorites list (just the id)
    QList<int>userFavorites;

    // Favorite page request list
    QList<FavsDialog*> pFDList;

    bool pmRequestedByUser;

    bool needDisplayNewsAtStartup;

    void createMenus(void);

protected:

    void closeEvent(QCloseEvent *pCE);

protected slots:

    // Requests to the web client
    void needLogin();
    void needLoadQueue();
    void needLoadOneliner();
    void needLoadStream();
    void needLoadNews();
    void needLoadFavs(void);
    void needLoadUserFavs(void);
    void needLoadSong();
    void needLoadArtist();
    void needLoadGroup();
    void needLoadCompilation();
    void needLoadUser(void);
    void needLoadUsers(void);
    void needLoadPMs(void);
    void needSetProxy();

    void needRefreshOneliner();
    void needRefreshQueue();
    void needDisplayStream();
    void needDisplayNews(void);
    void needDisplayFavList(void);
    void needDisplayFavListPage(void);
    void needDisplaySong(void);
    void needDisplayArtist(void);
    void needDisplayGroup(void);
    void needDisplayCompilation(void);
    void needDisplayUser(QString username);
    void needDisplayUsers(void);
    void needDisplayInbox(void);

    void needChangeOnelinerRefreshFreq(void);
    void needChangeUsersRefreshFreq(void);
    void needChangePMCheckFreq(void);
    void needTooglePMAutoCheck(void);

    void needGetFavPage(FavsDialog* pFD, const unsigned int pageNumber);
    void needFavSong(const int id);
    void needUnFavSong(const int id);
    void needRequestSong(const int id);

    void connectionSucceed(void);
    void needDisplayConnectionFailure(void);
    void needDisplayWebError(QString errorMessage);

    // Tabs closure
    void needTabToClose(int index);

    // Tabs opening (or making it current)
    void needOnelinerWidget(void);
    void needQueueWidget(void);
    void needPlayerWidget(void);

    // Player

    void tooglePlayPause(void);
    void toogleStopMenu(void);

    void needUpdatePlayerInfo(void);
    void needDisplayPlayerError(const QString errorMessage);

    void needUpdateUserFavorite(void);
    void needUpdateUserPaginatedFavorite(void);

    // Queue
    void needVote(int vote);

    // Oneliner
    void needSaveHistory(void);


    void needDeleteSID(SongInfoDialog* pSID);
    void needDeleteAID(ArtistInfoDialog* pAID);
    void needDeleteGID(GroupInfoDialog* pGID);
    void needDeleteCID(CompilationInfoDialog* pCID);
    void needDeleteUID(UserInfoDialog* pUID);
    void needDeleteFD(FavsDialog* pFD);

    // News prompt
    void needDeleteNPD(void);

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

    void closeOpenedWindows(void);

    // Loading settings of the application
    void loadSettings(void);
    // Saving settings of the application
    void saveSettings(void);
};

#endif // MAINWINDOW_H
